//
//  JLPZViewController.m
//  Estate
//
//  Created by heyong on 16/5/26.
//  Copyright © 2016年 ttsx. All rights reserved.
//
#define DIC_EXPANDED @"expanded" //是否是展开 0收缩 1展开
#define DIC_ARARRY @"array"
#define DIC_TITILESTRING @"title"
#define CELL_HEIGHT 46.0f

#import "SafeListCell.h"
#import "JLPZViewController.h"
#import "RJTableCell.h"
#import "recordModel.h"
#import "TTZhuanJianRightView.h"

@interface JLPZViewController ()
//侧边栏/
@property (strong ,nonatomic)TTZhuanJianRightView *rightView;
//所有监理员
@property (nonatomic,copy) NSMutableArray *jianliArr;
//选中监理员
@property (nonatomic,copy) NSMutableArray *jianliArrSelect;
@property (nonatomic,assign) BOOL isz;

@end

@implementation JLPZViewController

-(UITableView *)tableView{
    if(_tableView==nil){
        _tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, DEF_SCREEN_WIDTH, DEF_SCREEN_HEIGHT-44-49-50*BIZ)];
        _tableView.delegate=self;
        _tableView.dataSource=self;
        [_tableView registerNib:[UINib nibWithNibName:@"RJTableCell" bundle:nil] forCellReuseIdentifier:@"RJCell"];
        [_tableView registerNib:[UINib nibWithNibName:@"SafeListCell" bundle:nil] forCellReuseIdentifier:@"safeListCell"];
    }
    return _tableView;
}

- (NSMutableArray *)dataArray {
    if(_dataArray==nil){
        _dataArray=[NSMutableArray array];
    }
    return _dataArray;
}

- (PGSideRightView *)addView {
    if(_addView==nil){
        _addView=[[PGSideRightView alloc]initWithFrame:CGRectMake(kScreen_Width, 0, kScreen_Width, kScreen_Height)];
        NSArray* items = @[@{@"itemStr":@"交建",@"items":@[@"通用",@"桩基钢筋笼安放",@"灌注桩首盘砼浇筑",@"路面(沥青)混凝土摊铺",@"预应力张拉",@"预应力压浆"]},@{@"itemStr":@"房建",@"items":@[@"通用",@"防水施工",@"回填土施工",@"混凝土施工",@"混凝土灌注桩"]},];
        
        _addView.items = items;
        __weak typeof (self) weakSelf = self;
        _addView.selectVBlock = ^(NSString *itemStr, NSInteger section, NSInteger row) {
            if (section==1) {
                switch (row) {
                    case 0:
                        weakSelf.typzCtr.flag=@"addty";
                        //进入二级页面标识
                        weakSelf.typzCtr.isSubStr=@"flag";
                        [weakSelf.navigationController pushViewController:weakSelf.typzCtr animated:YES];
                        break;
                    case 1:
                        weakSelf.fssgCtr.flag=@"addty";
                        //进入二级页面标识
                        weakSelf.fssgCtr.isSubStr=@"flag";
                        [weakSelf.navigationController pushViewController:weakSelf.fssgCtr animated:YES];
                        break;
                    case 2:
                        weakSelf.httCtr.flag=@"addty";
                        //进入二级页面标识
                        weakSelf.httCtr.isSubStr=@"flag";
                        [weakSelf.navigationController pushViewController:weakSelf.httCtr animated:YES];
                        break;
                    case 3:
                        //新增标识
                        weakSelf.hntCtr.flag=@"addty";
                        //进入二级页面标识
                        weakSelf.hntCtr.isSubStr=@"flag";
                        [weakSelf.navigationController pushViewController:weakSelf.hntCtr animated:YES];
                        break;
                    case 4:
                        weakSelf.gzzCtr.flag=@"addty";
                        //进入二级页面标识
                        weakSelf.gzzCtr.isSubStr=@"flag";
                        [weakSelf.navigationController pushViewController:weakSelf.gzzCtr animated:YES];
                        break;
                    default:
                        break;
                }
            }else{
                //进入二级页面标识
                //交建类型
                NSArray *typeArr = @[@"RECORD_02_JJ_01",@"RECORD_02_JJ_02",@"RECORD_02_JJ_03",@"RECORD_02_JJ_04",@"RECORD_02_JJ_05",@"RECORD_02_JJ_06"];
                // 新增将原来的置空
                weakSelf.jjtyCtr.basicModel = nil;
                weakSelf.jjtyCtr.person = nil;
                weakSelf.jjtyCtr.machinery = nil;
                weakSelf.jjtyCtr.material = nil;
                weakSelf.jjtyCtr.fahuanTY = nil;
                weakSelf.jjtyCtr.fahuanZJ = nil;
                weakSelf.jjtyCtr.fahuanSP = nil;
                weakSelf.jjtyCtr.fahuanLM = nil;
                weakSelf.jjtyCtr.fahuanYJ = nil;
                weakSelf.jjtyCtr.fahuanZL = nil;
                
                weakSelf.jjtyCtr.flag = @"addty";
                weakSelf.jjtyCtr.isSubStr = typeArr[row];
                NSString *titleStr;
                if ([weakSelf.jjtyCtr.isSubStr isEqualToString:@"RECORD_02_JJ_01"]) {
                    titleStr = @"通用";
                    
                } else if ([weakSelf.jjtyCtr.isSubStr isEqualToString:@"RECORD_02_JJ_02"]) {
                    titleStr = @"桩基钢筋笼安放";
                    
                } else if ([weakSelf.jjtyCtr.isSubStr isEqualToString:@"RECORD_02_JJ_03"]) {
                    titleStr = @"灌注桩首盘砼浇筑";
                    
                } else if ([weakSelf.jjtyCtr.isSubStr isEqualToString:@"RECORD_02_JJ_04"]) {
                    titleStr = @"路面(沥青)混凝土摊铺";
                    
                } else if ([weakSelf.jjtyCtr.isSubStr isEqualToString:@"RECORD_02_JJ_05"]) {
                    titleStr = @"预应力张拉";
                    
                } else if ([weakSelf.jjtyCtr.isSubStr isEqualToString:@"RECORD_02_JJ_06"]) {
                    titleStr = @"预应力压浆";
                }
                weakSelf.jjtyCtr.title = [NSString stringWithFormat:@"旁站-交建-%@", titleStr];
                [weakSelf.navigationController pushViewController:weakSelf.jjtyCtr animated:YES];
            }
        };
    }
    return _addView;
}

-(JJTYPZViewController *)jjtyCtr{
    if (!_jjtyCtr) {
        _jjtyCtr = [[JJTYPZViewController alloc]init];
    }
    return _jjtyCtr;
}
- (TYPZViewController *)typzCtr{
    if(_typzCtr==nil){
        //通用
        _typzCtr=[[TYPZViewController alloc]init];
    }
    return _typzCtr;
}
- (FSSGViewController *)fssgCtr{
    if(_fssgCtr==nil){
        //防水施工
       _fssgCtr=[[FSSGViewController alloc]init];
    }
    return _fssgCtr;
}

- (HTTViewController *)httCtr{
    if(_httCtr==nil){
        //回填土
        _httCtr=[[HTTViewController alloc]init];
    }
    return _httCtr;
}

- (HNTViewController *)hntCtr{
    if(_hntCtr==nil){
        //混泥土
       _hntCtr=[[HNTViewController alloc]init];
    }
    return _hntCtr;
}

- (GZZViewController *)gzzCtr{
    if(_gzzCtr==nil){
        //灌注桩
        _gzzCtr=[[GZZViewController alloc]init];
    }
    return _gzzCtr;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view addSubview:self.tableView];
    self.tableView.tableFooterView=[[UIView alloc]initWithFrame:CGRectZero];
    self.view.backgroundColor=[UIColor colorWithRed:0.97 green:0.97 blue:0.97 alpha:1.00];
    self.tableView.backgroundColor=[UIColor colorWithRed:0.97 green:0.97 blue:0.97 alpha:1.00];
    [self createView];
    
    NSNotificationCenter * center = [NSNotificationCenter defaultCenter];
    [center addObserver:self selector:@selector(refresh:) name:@"Refresh_jl_pz" object:nil];
    NSString *role = DEF_PERSISTENT_GET_OBJECT(@"role");
    // 专业监理员
    if ([role isEqualToString:@"USER_07"]) {
        self.jianliArr = [LSUtility queryByType:@"USER_03"];
        self.jianliArrSelect = self.jianliArr;
        self.isz = YES;
        [self addShaixuanBtn];
        dispatch_async(dispatch_get_main_queue(), ^{
            UIWindow *myWindow=[UIApplication sharedApplication].keyWindow;
            [myWindow addSubview:self.listView];
        });
    }
    // 查找数据
    [self initDataSource];
}
-(NSString *)getUserIDWithArray:(NSMutableArray *)arr{
    if (self.isz) {
        NSString *str = [NSString stringWithFormat:@"\'%@\'",USERID];
        for (NSDictionary *dic in arr) {
            NSString *userid = dic[@"userid"];
            str=[str stringByAppendingString:[NSString stringWithFormat:@",\'%@\'",userid]];
        }
        return str;
        
    }else{
        NSString *str = @"";
        for (NSDictionary *dic in arr) {
            NSString *userid = dic[@"userid"];
            if ([str isEqualToString:@""]) {
                str = [NSString stringWithFormat:@"\'%@\'",userid];
            }else{
                str=[str stringByAppendingString:[NSString stringWithFormat:@",\'%@\'",userid]];
            }
        }
        return str;
    }
    
}
//懒加载
-(TTZhuanJianRightView *)listView{
    if(_rightView==nil){
        _rightView=[[TTZhuanJianRightView alloc]initWithFrame:CGRectMake(DEF_SCREEN_WIDTH,0,DEF_SCREEN_WIDTH, DEF_SCREEN_HEIGHT) dataArr:self.jianliArr];
        WEAKSELF
        _rightView.clickOkBtnBlock = ^(NSMutableArray *seleceArr) {
            if (seleceArr.count>0) {
                weakSelf.jianliArrSelect = seleceArr;
                weakSelf.isz = NO;
            }else{
                weakSelf.jianliArrSelect = weakSelf.jianliArr;
                weakSelf.isz = YES;
            }
            [weakSelf refresh:nil];
        };
    }
    return _rightView;
}
-(void)addShaixuanBtn{
    //弹出选择人物视图
    UIButton *rightBtn=[[UIButton alloc]initWithFrame:CGRECTS(DEF_SCREEN_WIDTH-70, 30, 70, 30)];
    rightBtn.tag=101;
    rightBtn.backgroundColor=[UIColor colorWithRed:0.78 green:0.26 blue:0.09 alpha:1.00];
    [rightBtn setTitle:@"人员选择" forState:UIControlStateNormal];
    rightBtn.titleLabel.font=[UIFont systemFontOfSize:13.];
    [rightBtn addTarget:self action:@selector(rightBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:rightBtn];
}
#pragma mark-添加按钮
- (void)rightBtnClick:(UIButton *)sender{
    
    [UIView animateWithDuration:0.4 animations:^{
        _rightView.frame =CGRectMake(0, 0, DEF_SCREEN_WIDTH, DEF_HEIGHT(self.view));
    }];
}

- (void)refresh:(id)sender{
    [self.dataArray removeAllObjects];
    [self initDataSource];
    [self.tableView reloadData];
}

//创建添加btn
- (void)createView{
    UIButton* addBtn=[[UIButton alloc]initWithFrame:CGRECTS(260, 360, 100, 100)];
    [addBtn setImage:[UIImage imageNamed:@"add_2"] forState:UIControlStateNormal];
    //设置旁站添加按钮
    [addBtn addTarget:self action:@selector(addContent:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:addBtn];
}


//初始化数据
- (void)initDataSource
{
    FMDatabase *db=[FMDatabase databaseWithPath:DEF_DB_DATABASEPATH];
    [db open];
    
    FMResultSet *result;
    NSString *role = DEF_PERSISTENT_GET_OBJECT(@"role");
    //专监
    if([role isEqualToString:@"USER_07"]){
        NSString *userids = [self getUserIDWithArray:self.jianliArrSelect];
        NSString *sql = [NSString stringWithFormat:@"SELECT COUNT(*),date(CREATE_TIME),substr(CREATE_TIME,1,4) as year,substr(CREATE_TIME,6,2) as month,substr(CREATE_TIME,9,2) as day FROM WORK_RECORD WHERE RECORD_TYPE in('RECORD_02_01','RECORD_02_02','RECORD_02_03','RECORD_02_04','RECORD_02_05','RECORD_02_JJ_01','RECORD_02_JJ_02','RECORD_02_JJ_03','RECORD_02_JJ_04','RECORD_02_JJ_05','RECORD_02_JJ_06') AND PRO_ID='%@' AND RECORD_USER in(%@)  GROUP BY date(CREATE_TIME) ORDER BY date(CREATE_TIME) desc", PROID, userids];
        result = [db executeQuery:sql];
    } else {
        result=[db executeQuery:SQL_WORKRESIDE_SELECT];
    }
    
//    NSLog(@"旁站列表查询:%@",SQL_WORKRESIDE_SELECT);
    NSMutableDictionary *dic;
    while ([result next]) {
        //查询到条件
        NSString* time= [result stringForColumn:@"date(CREATE_TIME)"];
        //查询到 年
        NSString* year= [result stringForColumn:@"year"];
        //查询到月
        NSString *month =[LSUtility deletaeZero:[result stringForColumn:@"month"]] ;
        //查询到日
        NSString *day =[LSUtility deletaeZero:[result stringForColumn:@"day"]] ;
        /*
         * 根据日期查询展开的数据
         */
        NSString *sqlStr = @"";
        //监理
        if ([role isEqualToString:@"USER_07"]){
            NSString *userids = [self getUserIDWithArray:self.jianliArrSelect];
            sqlStr=[NSString stringWithFormat:@"SELECT * ,time(CREATE_TIME) FROM WORK_RECORD AS wr WHERE  wr.RECORD_TYPE in('RECORD_02_01','RECORD_02_02','RECORD_02_03','RECORD_02_04','RECORD_02_05','RECORD_02_JJ_01','RECORD_02_JJ_02','RECORD_02_JJ_03','RECORD_02_JJ_04','RECORD_02_JJ_05','RECORD_02_JJ_06')  AND  date(CREATE_TIME) ='%@'  AND PRO_ID='%@' AND RECORD_USER in(%@) ORDER BY time(CREATE_TIME) desc",time,PROID,userids];
        }else{
           sqlStr =[NSString stringWithFormat:@"SELECT * ,time(CREATE_TIME) FROM WORK_RECORD AS wr WHERE  wr.RECORD_TYPE in('RECORD_02_01','RECORD_02_02','RECORD_02_03','RECORD_02_04','RECORD_02_05','RECORD_02_JJ_01','RECORD_02_JJ_02','RECORD_02_JJ_03','RECORD_02_JJ_04','RECORD_02_JJ_05','RECORD_02_JJ_06')  AND  date(CREATE_TIME) ='%@'  AND PRO_ID='%@' AND RECORD_USER='%@' ORDER BY time(CREATE_TIME) desc",time,PROID,USERID];
        }
        
        FMResultSet *results=[db executeQuery:sqlStr];

        //查询到记录
        NSMutableArray *DetailArr=[NSMutableArray array];
        while ([results next]) {
            recordModel *model=[[recordModel alloc]init];
            model.record_Id=[results stringForColumn:@"ID"];
            model.RECORD_TYPE=[results stringForColumn:@"RECORD_TYPE"];
            model.RECORD_USER=[results stringForColumn:@"RECORD_USER"];
            model.RECORD_TITLE=[results stringForColumn:@"RECORD_TITLE"];
            model.RECORD_FILE_PATH=[results stringForColumn:@"RECORD_FILE_PATH"];
            model.CREATE_TIME=[results stringForColumn:@"time(CREATE_TIME)"];
            model.ADDRESS_ID=[results stringForColumn:@"ADDRESS_ID"];
            model.ADDRES_INFO=[results stringForColumn:@"ADDRES_INFO"];
            model.EXTEND_INFO=[results stringForColumn:@"EXTEND_INFO"];
            model.PRO_ID=[results stringForColumn:@"PRO_ID"];
            model.WEATHER=[results stringForColumn:@"WEATHER"];
            model.RECORD_INFO=[results stringForColumn:@"RECORD_INFO"];
            model.RECORD_NUMBER=[results stringForColumn:@"RECORD_NUMBER"];
            [DetailArr addObject:model];
        }
        
        //查询到数量
        NSString *counts=[result stringForColumn:@"COUNT(*)"];
        //拼接成标题
        NSString *tiemAndCount=[NSString stringWithFormat:@"%@年%@月%@日(%@条)",year,month,day,counts];
        //标题添加到数组
        //        [array addObject:tiemAndCount];
        //创建一个字典 包含数组，分组名，是否展开的标示
        dic=[[NSMutableDictionary alloc] initWithObjectsAndKeys:DetailArr,DIC_ARARRY,tiemAndCount,DIC_TITILESTRING,[NSNumber numberWithInt:0],DIC_EXPANDED,nil];
        //将字典加入数组
        [self.dataArray addObject:dic];
    }
    [db close];
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.dataArray.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    NSMutableDictionary *dic=[self.dataArray objectAtIndex:section];
    NSArray *array=[dic objectForKey:DIC_ARARRY];
    //判断是收缩还是展开
    if ([[dic objectForKey:DIC_EXPANDED]intValue]) {
        return array.count;
    }else{
        return 0;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    long section=indexPath.section;
    long row=indexPath.row;
    //得到改组下信息
    NSMutableDictionary *dic=[self.dataArray objectAtIndex:section];
    NSArray *array=[dic objectForKey:DIC_ARARRY];
    recordModel *model=array[row];
    
//    if ([model.RECORD_TYPE isEqualToString:@"RECORD_02_01"]) {
    RJTableCell *cell=[tableView dequeueReusableCellWithIdentifier:@"RJCell" forIndexPath:indexPath];
    cell.state.hidden=YES;
    //赋值
    cell.type = model.RECORD_TYPE;
    cell.title.text=model.RECORD_TITLE;
    cell.time.text=model.CREATE_TIME;
    cell.name.text= [LSUtility getuserIdByUserName:model.RECORD_USER][@"REAL_NAME"];
    NSLog(@"%@",model.RECORD_TITLE);

    return cell;
//
//    } else {
//        SafeListCell *listCell = [tableView dequeueReusableCellWithIdentifier:@"safeListCell" forIndexPath:indexPath];
//        listCell.selectionStyle = NO;
//
//        // 通用
//        if ([model.RECORD_TYPE isEqualToString:@"RECORD_02_JJ_01"]) {
//            listCell.identificationImageView.image = [UIImage imageNamed:@"generalPurpose"];
//
//            // 桩基
//        } else if ([model.RECORD_TYPE isEqualToString:@"RECORD_02_JJ_02"]) {
//            listCell.identificationImageView.image = [UIImage imageNamed:@"pileFoundation"];
//
//            // 首盘
//        } else if ([model.RECORD_TYPE isEqualToString:@"RECORD_02_JJ_03"]) {
//            listCell.identificationImageView.image = [UIImage imageNamed:@"firstMixedSoil"];
//
//            // 沥青
//        } else if ([model.RECORD_TYPE isEqualToString:@"RECORD_02_JJ_04"]) {
//            listCell.identificationImageView.image = [UIImage imageNamed:@"asphalt"];
//
//            // 预应力张拉
//        } else if ([model.RECORD_TYPE isEqualToString:@"RECORD_02_JJ_05"]) {
//            listCell.identificationImageView.image = [UIImage imageNamed:@"tensile"];
//
//            // 预应力压浆
//        } else if ([model.RECORD_TYPE isEqualToString:@"RECORD_02_JJ_06"]) {
//            listCell.identificationImageView.image = [UIImage imageNamed:@"grouting"];
//        }
        
//        // 标题
//        listCell.titleLabel.text = model.RECORD_TITLE;
//        // 姓名
//        listCell.peopleLabel.text = [LSUtility getuserIdByUserName:model.RECORD_USER][@"REAL_NAME"];
//        // 时间
//        listCell.timeLabel.text = model.CREATE_TIME;
//        // 位置
//        NSDictionary *exDic = [LSUtility dictionaryWithJsonString:model.ADDRES_INFO];
//        listCell.areaLabel.text = exDic[@"leftDistanceStr"];
//        return listCell;
//    }
}

//设置分组头的视图
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *hView = [[UIView alloc]initWithFrame:CGRectMake(0,0, DEF_SCREEN_WIDTH, CELL_HEIGHT-10)];
    hView.backgroundColor=[UIColor colorWithRed:0.94 green:0.94 blue:0.94 alpha:1.00];
    UIButton* eButton = [[UIButton alloc] init];
    eButton.backgroundColor=[UIColor whiteColor];
    //按钮填充整个视图
    eButton.frame = hView.frame;
    [eButton addTarget:self action:@selector(expandButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
    //把节号保存到按钮tag，以便传递到expandButtonClicked方法
    eButton.tag = section;
    //根据是否展开，切换按钮显示图片
    if ([self isExpanded:section])
        [eButton setImage:  [UIImage imageNamed: @"xiala" ]forState:UIControlStateNormal];
    else
        [eButton setImage: [UIImage imageNamed: @"gengduo1" ]forState:UIControlStateNormal];
    
    //设置分组标题
    [eButton setTitle:[[self.dataArray objectAtIndex:section] objectForKey:DIC_TITILESTRING]forState:UIControlStateNormal];
    
    [eButton setTitleColor:[UIColor colorWithRed:0.68 green:0.68 blue:0.68 alpha:1.00] forState:UIControlStateNormal];
    //设置字体样式
    eButton.titleLabel.font=[UIFont systemFontOfSize:16.*BIZ];
    
    //设置button的图片和标题的相对位置
    
    //4个参数是到上边界，左边界，下边界，右边界的距离
    eButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [eButton setTitleEdgeInsets:UIEdgeInsetsMake(0,5, 0,0)];
    [eButton setImageEdgeInsets:UIEdgeInsetsMake(0,DEF_SCREEN_WIDTH-30, 0,0)];
    
    //添加btn
    [hView addSubview: eButton];
    
    return hView;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    //判断是收缩还是展开
    NSMutableDictionary *dic=[self.dataArray objectAtIndex:section];
    if ([[dic objectForKey:DIC_EXPANDED]intValue]) {
        return 10;
    }else{
        return 0;
    }
}

//控制表头分组表头高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 46*BIZ;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 70*BIZ;
}

#pragma mark-点击表格
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
/*
 *  根据类型 跳转到不同的页面
 *  房建类型
 *  工作记录类型——旁站——通用 "RECORD_02_01";
 *  工作记录类型——旁站——卷材防水 "RECORD_02_02"
 *  工作记录类型——旁站——回填土     RECORD_02_03"
 *  工作记录类型——旁站——混凝土施工    RECORD_02_04"
 *  工作记录类型——旁站——混凝土灌注桩  RECORD_02_05
 *
 *  交建类型
 *  通用：RECORD_02_JJ_01
 *  桩基钢筋笼安放：RECORD_02_JJ_02
 *  灌注桩首盘砼浇筑：RECORD_02_JJ_03
 *  路面（沥青）混凝土铺盖：RECORD_02_JJ_04
 *  预应力张拉：RECORD_02_JJ_05
 *  预应力压浆：RECORD_02_JJ_06
 */
    
    //得到改组下信息
    NSMutableDictionary *dic=[self.dataArray objectAtIndex:indexPath.section];
    NSArray *array=[dic objectForKey:DIC_ARARRY];
    recordModel *model=array[indexPath.row];
    NSString *type=model.RECORD_TYPE;
    
    //
    if([type isEqualToString:@"RECORD_02_01"]){
        self.typzCtr.sideId=model.record_Id;
        self.typzCtr.flag=@"upRecord";
        self.typzCtr.isSubStr=@"flag";
        [self.navigationController pushViewController:self.typzCtr animated:YES];
        
    } else if ([type isEqualToString:@"RECORD_02_02"]){
        self.fssgCtr.sideId=model.record_Id;
        self.fssgCtr.flag=@"upRecord";
        self.fssgCtr.isSubStr=@"flag";
        [self.navigationController pushViewController:self.fssgCtr animated:YES];
        
    }else if ([type isEqualToString:@"RECORD_02_03"]){
        self.httCtr.sideId=model.record_Id;
        self.httCtr.flag=@"upRecord";
         self.httCtr.isSubStr=@"flag";
        [self.navigationController pushViewController:self.httCtr animated:YES];
        
    } else if ([type isEqualToString:@"RECORD_02_04"]){
        self.hntCtr.sideId=model.record_Id;
        self.hntCtr.flag=@"upRecord";
        //进入二级页面标识
        self.hntCtr.isSubStr=@"flag";
        [self.navigationController pushViewController:self.hntCtr animated:YES];
        
    } else if ([type isEqualToString:@"RECORD_02_05"]){
        self.gzzCtr.sideId=model.record_Id;
        self.gzzCtr.flag=@"upRecord";
        //进入二级页面标识
        self.gzzCtr.isSubStr=@"flag";
        [self.navigationController pushViewController:self.gzzCtr animated:YES];
        
    // 交建类型
    }else{
        self.jjtyCtr.isSubStr= type;
        self.jjtyCtr.sideId = model.record_Id;
        self.jjtyCtr.flag = @"upRecord";
        [self.navigationController pushViewController:self.jjtyCtr animated:YES];
    }
}

#pragma mark -- 内部调用
//对指定的节进行“展开/折叠”操作,若原来是折叠的则展开，若原来是展开的则折叠

-(void)collapseOrExpand:(long)section{
    NSMutableDictionary *dic=[self.dataArray objectAtIndex:section];
    int expanded=[[dic objectForKey:DIC_EXPANDED] intValue];
    if (expanded) {
        [dic setValue:[NSNumber numberWithInt:0]forKey:DIC_EXPANDED];
    }else
    {
        [dic setValue:[NSNumber numberWithInt:1]forKey:DIC_EXPANDED];
    }
}

//返回指定节是否是展开的

-(int)isExpanded:(long)section{
    NSDictionary *dic=[self.dataArray objectAtIndex:section];
    int expanded=[[dic objectForKey:DIC_EXPANDED] intValue];
    return expanded;
}

//按钮被点击时触发
-(void)expandButtonClicked:(id)sender{
    UIButton* btn= (UIButton*)sender;
    long section= btn.tag;//取得tag知道点击对应哪个块
    [self collapseOrExpand:section];
    //刷新tableview
    [self.tableView reloadData];
}

#pragma  mark -显示旁站信息
- (void)addContent:(UIButton *)sender{
    if(!self.addView.isShowInView){
        [self.addView showInView:[UIApplication sharedApplication].keyWindow];
    }else{
        [self.addView hideFromView];
    }
}

@end
